package GUI;

import Model.Product;
import Model.SalesOrderProduct;

import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

public class NewOrderTableModel extends DefaultTableModel {

    private ArrayList<SalesOrderProduct> data;

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    public void setData(ArrayList<SalesOrderProduct> data) {
        this.data = data;
        fireTableDataChanged();
    }

    public ArrayList<SalesOrderProduct> getData() {
        return data;
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public int getRowCount() {
        if(data == null) {
            return 0;
        }
        else {
            return data.size();
        }
    }

    @Override
    public String getColumnName(int column) {
        String columnName = "";
        switch (column) {
            case 0:
                columnName ="ID";
                break;
            case 1:
                columnName = "Name";
                break;
            case 2:
                columnName = "Price";
                break;
            case 3:
                columnName = "Amount";
                break;

        }
        return columnName;
    }


    @Override
    public Object getValueAt(int row, int column) {
        Object value = null;
        switch (column) {
            case 0:
                value = data.get(row).getProduct().getId();
                break;
            case 1:
                value = data.get(row).getProduct().getName();
                break;
            case 2:
                value = data.get(row).getProduct().getSalesPrice();
                break;
            case 3:
                value = data.get(row).getAmount();
                break;
        }

        return value;
    }

}
